6
<template>
	<div class="layout-padding">
		<div class="layout-padding-auto layout-padding-view">
			<el-row v-show="showSearch">
				<el-form :model="state.queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList">
					<el-form-item :label="$t('company.proprietor')" prop="proprietor">
						<el-input :placeholder="t('company.inputProprietorTip')" v-model="state.queryForm.proprietor" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.supplier')" prop="supplier">
						<el-input :placeholder="t('company.inputSupplierTip')" v-model="state.queryForm.supplier" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.placeOfDelivery')" prop="placeOfDelivery">
						<el-input :placeholder="t('company.inputPlaceOfDeliveryTip')" v-model="state.queryForm.placeOfDelivery" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.placeOfDispatch')" prop="placeOfDispatch">
						<el-input :placeholder="t('company.inputPlaceOfDispatchTip')" v-model="state.queryForm.placeOfDispatch" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.weight')" prop="weight">
						<el-input :placeholder="t('company.inputWeightTip')" v-model="state.queryForm.weight" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.totalPrice')" prop="totalPrice">
						<el-input :placeholder="t('company.inputTotalPriceTip')" v-model="state.queryForm.totalPrice" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.price')" prop="price">
						<el-input :placeholder="t('company.inputPriceTip')" v-model="state.queryForm.price" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.breed')" prop="breed">
						<el-input :placeholder="t('company.inputBreedTip')" v-model="state.queryForm.breed" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.quality')" prop="quality">
						<el-input :placeholder="t('company.inputQualityTip')" v-model="state.queryForm.quality" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.settlementMethod')" prop="settlementMethod">
						<el-input :placeholder="t('company.inputSettlementMethodTip')" v-model="state.queryForm.settlementMethod" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.dealDate')" prop="dealDate">
						<el-input :placeholder="t('company.inputDealDateTip')" v-model="state.queryForm.dealDate" style="max-width: 180px" />
					</el-form-item>
					<el-form-item :label="$t('company.createDate')" prop="createDate">
						<el-input :placeholder="t('company.inputCreateDateTip')" v-model="state.queryForm.createDate" style="max-width: 180px" />
					</el-form-item>
					<el-form-item>
						<el-button formDialogRef icon="search" type="primary" @click="getDataList">
							{{ $t('common.queryBtn') }}
						</el-button>
						<el-button icon="Refresh" formDialogRef @click="resetQuery">{{ $t('common.resetBtn') }}</el-button>
					</el-form-item>
				</el-form>
			</el-row>
			<el-row>
				<div class="mb8" style="width: 100%">
					<el-button
						formDialogRef
						icon="folder-add"
						type="primary"
						class="ml10"
						@click="formDialogRef.openDialog()"
						v-auth="'coalSystem_company_add'"
					>
						{{ $t('common.addBtn') }}
					</el-button>
					<el-button
						plain
						formDialogRef
						:disabled="multiple"
						icon="Delete"
						type="primary"
						class="ml10"
						v-auth="'coalSystem_company_del'"
						@click="handleDelete(selectObjs)"
					>
						{{ $t('common.delBtn') }}
					</el-button>
					<right-toolbar
						v-model:showSearch="showSearch"
						:export="'coalSystem_company_export'"
						@exportExcel="exportExcel"
						class="ml10"
						style="float: right; margin-right: 20px"
						@queryTable="getDataList"
					></right-toolbar>
				</div>
			</el-row>
			<el-table
				:data="state.dataList"
				v-loading="state.loading"
				style="width: 100%"
				@selection-change="handleSelectionChange"
				@sort-change="sortChangeHandle"
			>
				<el-table-column type="selection" width="40" align="center" />
				<el-table-column type="index" :label="t('company.index')" width="40" />
				<el-table-column prop="proprietor" :label="t('company.proprietor')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="supplier" :label="t('company.supplier')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="placeOfDelivery" :label="t('company.placeOfDelivery')" show-overflow-tooltip />
				<el-table-column prop="placeOfDispatch" :label="t('company.placeOfDispatch')" show-overflow-tooltip />
				<el-table-column prop="weight" :label="t('company.weight')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="totalPrice" :label="t('company.totalPrice')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="price" :label="t('company.price')" show-overflow-tooltip />
				<el-table-column prop="breed" :label="t('company.breed')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="quality" :label="t('company.quality')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="settlementMethod" :label="t('company.settlementMethod')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="dealDate" :label="t('company.dealDate')" sortable="custom" show-overflow-tooltip />
				<el-table-column prop="createDate" :label="t('company.createDate')" sortable="custom" show-overflow-tooltip />
				<el-table-column :label="$t('common.action')" width="150">
					<template #default="scope">
						<el-button
							icon="edit-pen"
							text
							type="primary"
							v-auth="'coalSystem_company_edit'"
							@click="formDialogRef.openDialog(scope.row.coalCompanyId)"
							>{{ $t('common.editBtn') }}</el-button
						>
						<el-button icon="delete" text type="primary" v-auth="'coalSystem_company_del'" @click="handleDelete([scope.row.coalCompanyId])">{{
							$t('common.delBtn')
						}}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" v-bind="state.pagination" />
		</div>

		<!-- 编辑、新增  -->
		<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />
	</div>
</template>

<script setup lang="ts" name="systemCoalCompany">
import { BasicTableProps, useTable } from '/@/hooks/table';
import { fetchList, delObjs } from '/@/api/coalSystem/company';
import { useMessage, useMessageBox } from '/@/hooks/message';
import { useDict } from '/@/hooks/dict';
import { useI18n } from 'vue-i18n';

// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
const { t } = useI18n();
// 定义查询字典

// 定义变量内容
const formDialogRef = ref();
// 搜索变量
const queryRef = ref();
const showSearch = ref(true);
// 多选变量
const selectObjs = ref([]) as any;
const multiple = ref(true);

const state: BasicTableProps = reactive<BasicTableProps>({
	queryForm: {},
	pageList: fetchList,
});

//  table hook
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile } = useTable(state);

// 清空搜索条件
const resetQuery = () => {
	// 清空搜索条件
	queryRef.value?.resetFields();
	// 清空多选
	selectObjs.value = [];
	getDataList();
};

// 导出excel
const exportExcel = () => {
	downBlobFile('/coalSystem/company/export', state.queryForm, 'company.xlsx');
};

// 多选事件
const handleSelectionChange = (objs: any) => {
	selectObjs.value.push(...objs.map((val: any) => val.coalCompanyId));
	multiple.value = !objs.length;
};

// 删除操作
const handleDelete = async (ids: string[]) => {
	try {
		await useMessageBox().confirm(t('common.delConfirmText'));
	} catch {
		return;
	}

	try {
		await delObj(ids);
		getDataList();
		useMessage().success(t('common.delSuccessText'));
	} catch (err: any) {
		useMessage().error(err.msg);
	}
};
</script>
